home *** CD-ROM | disk | FTP | other *** search
- /*********************************************************
- "idle.c"
-
- by John A. Love, III [ Washington Apple Pi Users' Group]
-
- using Symantec's "THINK C", v 5.00
- *********************************************************/
-
-
- #include <Balloons.h>
-
- #include "protos"
-
- #include "globals.h"
- #include "extern.h"
-
- #include "about.h"
- #include "floatingWindow.h"
-
-
-
-
- void SetEnable (MenuHandle menu, short item, Boolean enabled);
- Boolean daMenu (void);
-
-
- #define wholeMenu 0
- extern Boolean currEdit; // in "menu.c"
- extern Boolean currAppWind; // in "window.c"
- extern long Sleep; // in "event.c"
- extern DialogPtr helpPtr; // in "about.c" ...
- extern HelpInfoHdl hHTBL;
- extern short First_Menu, Last_Menu;
-
-
-
-
- void DoPeriodic (void) {
-
-
- if (!gWNE) SystemTask;
-
- gMac2 = TestForColor(&gColorDepth);
- if (Sleep == 1) Sleep = GetCaretTime(); // Reset after special effects.
- PeriodicWindows(); // Feeds PeriodicMenus & HandleCursor ...
- PeriodicMenus();
- HandleCursor();
-
- if (gInForeGround)
- {
- gBalloonsUp = BalloonsOn();
- FindAndShowDynamicBalloons(gBalloonsUp);
-
- // Problems with "Switch-A-Roo" ...
- // It eliminates my Help MENU item. }
- //
- // For some ??? reason the next two IFs are required here
- // even though "SetupMainMenus" would NOT have a non-NIL
- // Help MenuHandle unless they were true.
- if (HelpManagerActive())
- if (HMGetHelpMenuHandle(&gHelpMenu) == noErr)
- if (gHelpMenu != nil)
- if (CountMItems(gHelpMenu) == gOrigNumHelpItems)
- AppendMenu(gHelpMenu, "\pAbout my application ...");
- }
- else gStartBalloons = BalloonsOn(); // Stab me in the back !!
-
- } /* DoPeriodic */
-
-
-
- /* -------------------
- ** To be or NOT to be !!
- ** ------------------- */
-
- void SetEnable (MenuHandle menu, short item, Boolean enabled) {
-
-
- if (enabled) EnableItem(menu, item);
- else DisableItem(menu, item);
-
- } /* SetEnable */
-
-
-
- /* -----------------------------------------------------------------
- ** PeriodicMenus is called before action is taken on menu commands
- ** to correctly enable or disable the "Edit" Menu in case a Desk
- ** Accessory owns the front window or no window is up, respectively.
- ** The latter also affects individual items in the other Menu(s).
- ** ----------------------------------------------------------------- */
-
- void PeriodicMenus (void) {
-
- Boolean myAppWind;
- Boolean redraw = false; // Initialized EVERY time !!
-
-
- /* MultiFinder switches our MENUs out to a different layer. */
- if (!gInForeGround) return;
-
- /* PeriodicHelp() handles MENUs if the HTBL window is in front: */
- if (PeriodicHelp()) return;
-
- myAppWind = (gFW != nil) && (!gCurrDA);
-
- // SetEnable(gFileMenu, NewWindowItem, !gCurrDA);
-
- if (myAppWind != currAppWind) /* No need to repeat yourself !! */
- {
- EnableItem(gFileMenu, wholeMenu);
- redraw = true;
- currAppWind = myAppWind; /* Reset. */
- }
-
- // SetEnable(gFileMenu, CloseWindowItem, myAppWind);
-
- if ((myAppWind || gCurrDA) != currEdit) /* Avoid a flickering Menu Bar. */
- {
- if (myAppWind || gCurrDA) EnableItem(gEditMenu, wholeMenu);
- else DisableItem(gEditMenu, wholeMenu);
- ;
- currEdit = myAppWind || gCurrDA; /* Reset. */
- redraw = true;
- }
-
- if (redraw) DrawMenuBar();
-
- } /* PeriodicMenus */
-
-
-
- Boolean daMenu (void) {
- /* I know ... NEVER assume knowledge of Menu Record structures ... BUT ... */
-
- #define MenuListLoc 0xA1C
-
- typedef struct rMenuRec {
- MenuHandle menuOH;
- short menuLeft; /* Left edge of Menu. */
- } rMenuRec;
-
- typedef struct hMenuRec {
- MenuHandle menuHOH;
- short reserved;
- } hMenuRec;
-
- typedef struct MenuList {
- short lastMenu; /* Offset to last regular MenuHandle. */
- short lastRight; /* Right edge of last Menu's title. */
- short mbResID;
- rMenuRec rMenu[];
- // The following fields are also present:
- //
- // short lastHMenu; -- Offset from here to last
- // hierarchical Menu.
- // PixMapHandle menuTitleSave;
- // hMenuRec hMenu[]; -- When my daMenu routine is called,
- // there are NO hierarchical Menus.
- } MenuList, *MenuListPtr, **MenuListHdl;
-
-
- MenuListHdl MLHdl = (MenuListHdl) (* (longPtr)(MenuListLoc) );
- short nbrMenusX6, menuCounter, theMenuID;
-
-
- nbrMenusX6 = (*MLHdl)->lastMenu;
- menuCounter = (nbrMenusX6 / 6) - 1;
-
- while (menuCounter >= 0)
- {
- theMenuID = (* (*MLHdl)->rMenu[menuCounter].menuOH )->menuID;
- // Watch out !!! with System 7 ...
- // ... the Help Menu (kHMHelpMenuID = -16490) &
- // ... the Application Menu (ID = ???)
- if ((theMenuID < 0) && (theMenuID >= -16384)) break;
- --menuCounter;
- } /* scanning the MenuBar */
-
- // I could have used
- // daMenu = theMenuID < 0;
- // because I KNOW my app has menus. However, to make this routine
- // applicable to ANY app, what if ANY app had zip menus and there
- // were no DA menus, I would have to initialize with
- // theMenuID = 0;
- // putting an extra statement in a time-critical "doPeriodic" loop.
- return (menuCounter >= 0);
-
- } /* daMenu */
-
-
-
- void PeriodicWindows (void) {
-
-
- /* Used by HandleCursor and other routines: */
- gFW = TFrontWindow(anyKind);
- gCurrDA = (TFrontWindow(systemKind) != nil) || daMenu();
-
- } /* PeriodicWindows */
-
-
-
- Boolean PeriodicHelp (void) {
- /* Handles MENUs if Help Window is in front. */
-
- short theMenuID;
- static Boolean HjustActivated = false; // Initialized ONLY once !!
-
-
- if ((helpPtr == nil) || !((WindowPeek)helpPtr)->hilited) {
- HjustActivated = false;
- return (false);
- }
- else {
- if (!HjustActivated) /* Don't stutter !! */ {
- for (theMenuID = First_Menu; theMenuID <= Last_Menu; theMenuID++)
- DisableItem(GetMHandle(theMenuID), wholeMenu);
- DrawMenuBar();
- ;
- // Set globals to opposite so MenuBar is re-drawn
- // when Help Window is closed or de-activated:
- currEdit = !currEdit;
- currAppWind = !currAppWind;
- ;
- HjustActivated = true;
- }
- return (true);
- }
-
- } /* PeriodicHelp */
-
-
-
-
- /* { end file "idle.c" } */
-